﻿using ExcelFileMonitor.NPOI.Config;
using ExcelFileMonitor.NPOI.Models;
using ExcelFileMonitor.NPOI.Utilities;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ExcelFileMonitor.NPOI.Services
{
    public interface IExcelFileWatcher : IDisposable
    {
        event EventHandler<ExcelFileEvent> FileDetected;
        event EventHandler<Exception> ErrorOccurred;
        event EventHandler<string> StatusChanged;

        string RootMonitorPath { get; }
        bool IsWatching { get; }
        int ActiveProcesses { get; }
        int TotalFilesDetected { get; }
        IReadOnlyCollection<string> CurrentFiles { get; }

        Task StartWatchingAsync();
        Task StopWatchingAsync();
        Task ScanExistingFilesAsync();

        Task<bool> VerifyFileAccessAsync(string filePath);
        Task<FileHealthCheck> CheckFileHealthAsync(string filePath);
    }

    public class FileHealthCheck
    {
        public string FilePath { get; set; }
        public bool IsAccessible { get; set; }
        public bool IsExcelFile { get; set; }
        public long FileSize { get; set; }
        public DateTime LastModified { get; set; }
        public Exception Error { get; set; }
        public TimeSpan CheckDuration { get; set; }

        public override string ToString()
        {
            return $"File: {System.IO.Path.GetFileName(FilePath)}, Accessible: {IsAccessible}, Size: {FileSize} bytes";
        }
    }
}
